package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController(value="userSetmealController")
@RequestMapping("/user/setmeal")
@Api(tags = "用户端套餐相关接口")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 获取套餐列表
     */
    @GetMapping("/list")
    @Cacheable(cacheNames = "setmealCache",key="#categoryId")  //计算得到的key：setmealCache::{categoryId} value:方法的返回结果，即为Resul
    @ApiOperation("用户端根据CategoryId获取套餐列表")
    public Result<List<Setmeal>> listSetmeal(Long categoryId){
        log.info("获取套餐列表，CategoryId={}",categoryId);
        List<Setmeal> list=setmealService.listSetmealOnSale(categoryId);
        return Result.success(list);
    }

    /**
     * 获取套餐的菜品信息
     */
    @GetMapping("/dish/{id}")
    @ApiOperation("获取套餐信息")
    public Result<List<DishItemVO>> getSetmealDish(@PathVariable Long id){
        log.info("获取套餐的菜品信息，setmealId={}",id);
        List<DishItemVO> list=setmealService.getSetmealDishes(id);
        return Result.success(list);
    }

}
